export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: '电子商城',
    htmlAttrs: {
      lang: 'en'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/icon.ico' }
    ]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    'iview/dist/styles/iview.css'
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    '@/plugins/iview',
    { src: '@/plugins/encrypt.js', ssr: false }
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
  ],

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    extractCSS: process.env.NODE_ENV === 'production',
    optimization: {
      splitChunks: {
        cacheGroups: {
          styles: {
            name: 'styles',
            test: /\.(css|vue|scss)$/,
            chunks: 'all',
            enforce: true
          }
        }
      }
    },
    extend(config, ctx) {
    }
  },
  dev: {
    extractCSS: process.env.NODE_ENV !== 'production',
    optimization: {
      splitChunks: {
        cacheGroups: {
          styles: {
            name: 'styles',
            test: /\.(css|vue|scss)$/,
            chunks: 'all',
            enforce: true
          }
        }
      }
    },
    extend(config, ctx) {
    }
  },
  router: {
    // 中间件-路由守卫
    middleware: 'auth',
    // 扩展路由
    extendRoutes(routes, resolve) {
      routes.push(
        {
          path: '/', // 首页
          name: 'Index',
          component: resolve(__dirname, 'pages/index/Index.vue')
        },
        {
          path: '/login', // 登录
          name: 'Login',
          component: resolve(__dirname, 'pages/login/Login.vue')
        },
        {
          path: '/signUp', // 注册
          component: resolve(__dirname, 'pages/signUp/SignUp.vue'),
          children: [
            {
              path: '/',
              name: 'SignIndex',
              component: resolve(__dirname, 'components/signUp/CheckPhone.vue')
            },
            // {
            //   path: 'checkPhone',
            //   name: 'CheckPhone',
            //   component: resolve(__dirname, 'components/signUp/CheckPhone.vue')
            // },
            {
              path: 'inputInfo',
              name: 'InputInfo',
              component: resolve(__dirname, 'components/signUp/InputInfo.vue')
            },
            {
              path: 'signUpDone',
              name: 'SignUpDone',
              component: resolve(__dirname, 'components/signUp/SignUpDone.vue')
            }
          ]
        },
        {
          path: '/goodsList', // 商品列表
          name: 'GoodsList',
          component: resolve(__dirname, 'pages/goodsList/GoodsList.vue')
        },
        {
          path: '/goodsDetail', // 商品详情
          name: 'GoodsDetail',
          component: resolve(__dirname, 'pages/goodsDetail/GoodsDetail.vue')
        },
        {
          path: '/successfullyAdd', // 添加购物车成功
          name: 'SuccessfullyAdd',
          component: resolve(__dirname, 'pages/successfullyAdd/SuccessfullyAdd.vue')
        },
        {
          path: '/order', // 订单页面
          name: 'Order',
          component: resolve(__dirname, 'pages/order/Order.vue')
        },
        {
          path: '/pay', // 支付页面
          name: 'Pay',
          component: resolve(__dirname, 'pages/pay/Pay.vue')
        },
        {
          path: '/payDone', // 支付成功页面
          name: 'PayDone',
          component: resolve(__dirname, 'pages/pay/PayDone.vue')
        },
        {
          path: '/freeback', // 反馈页面
          name: 'Freeback',
          component: resolve(__dirname, 'pages/freeback/Freeback.vue')
        },
        {
          path: '/home', // 主页
          component: resolve(__dirname, 'pages/userHome/Home.vue'),
          children: [
            {
              path: '/',
              name: 'HomeIndex',
              component: resolve(__dirname, 'components/home/MyShoppingCart.vue')
            },
            {
              path: 'myAddress',
              name: 'MyAddress',
              component: resolve(__dirname, 'components/home/MyAddress.vue')
            },
            {
              path: 'addAddress',
              name: 'AddAddress',
              component: resolve(__dirname, 'components/home/AddAddress.vue')
            },
            {
              path: 'myOrder',
              name: 'MyOrder',
              component: resolve(__dirname, 'components/home/MyOrder.vue')
            },
            {
              path: 'myShoppingCart',
              name: 'MyShoppingCart',
              component: resolve(__dirname, 'components/home/MyShoppingCart.vue')
            }
          ]
        },
        {
          path: '/404',
          component: resolve(__dirname, 'pages/error-page/404.vue')
        },
        { path: '*', redirect: '/404', hidden: true }
      )
    }
  }
}
